//
//  HXIflyJobRecordTableViewCell.m
//  KD
//
//  Created by ifly on 16/7/8.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXIflyJobRecordTableViewCell.h"
#import "NSString+Frame.h"
#import "HXIflyPersonalDataTableViewController.h"

@implementation HXIflyJobRecordTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    //头像
    _userImageView.image = [UIImage imageNamed:@"tx@3x"];
//    _personPhotoBtn.layer.cornerRadius = 8;
//    _personPhotoBtn.layer.masksToBounds = YES;
//    [_personPhotoBtn setImage:[UIImage imageNamed:@"tx@3x"] forState:UIControlStateNormal];
    [_personPhotoBtn addTarget:self action:@selector(personPhotoBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    //评论
    //[self.commentBtn setImage:[UIImage imageNamed:@"addMan"] forState:UIControlStateNormal];
//    [self.commentBtn setTitle:@"" forState:UIControlStateNormal];
    [_commentBtn addTarget:self action:@selector(commentBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    //看过
//    [self.readBtn setImage:[UIImage imageNamed:@"add01@3x"] forState:UIControlStateNormal];
//    [self.readBtn setTitle:@"" forState:UIControlStateNormal];
    [_readBtn addTarget:self action:@selector(readBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)setDayWorkModel:(HXGetMembersDayWorkListModel *)dayWorkModel{

    _dayWorkModel = dayWorkModel;
    _personNameLabel.text = _dayWorkModel.SendUserName;

    //截取时间
    NSRange sendTimeRange = NSMakeRange(5, _dayWorkModel.SendDate.length - 5);
    NSString * sendTime = [_dayWorkModel.SendDate substringWithRange:sendTimeRange];
    _sendTimeLabel.text = sendTime;
    
    NSRange publishRange = NSMakeRange(0,10);
    NSString * publishStr = [_dayWorkModel.SendDate substringWithRange:publishRange];
    _publishLabel.text = [NSString stringWithFormat:@"日报(%@)",publishStr];
    
    //内容
    CGFloat connetLabelHeight = [_dayWorkModel.Content heightWithFont:[UIFont systemFontOfSize:16] withinWidth:HXSCREEN_WIDTH-3*8];
    
    _connetLabel.frame = CGRectMake(_connetLabel.x, _connetLabel.y, _connetLabel.width, connetLabelHeight);
    _connetLabel.text = _dayWorkModel.Content;
    
    //评论
    if ([_dayWorkModel.ReplyCount integerValue] > 0) {
        
        [_commentBtn setTitle:[NSString stringWithFormat:@" 评论(%@)",_dayWorkModel.ReplyCount] forState:UIControlStateNormal];
    }
    
    //看过
    if ([_dayWorkModel.ReadCount integerValue] > 0) {
        
        [_readBtn setTitle:[NSString stringWithFormat:@" 看过(%@)",_dayWorkModel.ReadCount] forState:UIControlStateNormal];
    }
    
}

-(void)setGroupId:(NSString *)groupId{

    _groupId = groupId;
}

-(void)personPhotoBtnClick {
    
//    HXGetGroupMembersListModel * model = self.dataArr[indexPath.row];
    
    if (!_isLastViewDetail) {
        
        HXIflyPersonalDataTableViewController * personalDataVc = [[HXIflyPersonalDataTableViewController alloc] initWithUserID:_dayWorkModel.SendUserID withGroupsId:self.groupId];
        
        [self.viewController.navigationController pushViewController:personalDataVc animated:YES];
    }
}

-(void)commentBtnClick {

    
}

-(void)readBtnClick {
    
    //看过
    if ([_dayWorkModel.ReadCount integerValue] > 0) {
    
        [NetworkAPI getLookTimesWithMessageID:self.dayWorkModel.MessageID
                                      Success:^(HXGetLookTimesModel *result) {
                                          NSMutableString * nsmuStr = [[NSMutableString alloc] init];
                                          for (int i = 0; i<result.result.count; i++) {
                                              HXGetLookTimesListModel * model = result.result[i];
                                              
                                              [nsmuStr appendFormat:@"%@,",model.PersonName];
                                          }
                                          NSRange rang = NSMakeRange(0, nsmuStr.length - 1);
                                          
                                          NSString * peopleStr = [nsmuStr substringWithRange:rang];
                                          
                                          [LTAlertView showTitle:@"看过的人" message:peopleStr ButtonTitles:@[@"确定"] OnTapBlock:^(LTAlertView *alert, NSInteger num) {
                                              
                                          }];
                                          
                                      } failure:^(NSError *err) {
                                          
                                      }];
    }
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
